package fr.adfm.ws.SC;

import fr.adfm.paiement.data.ProcessContext;
import fr.adfm.proxy.SC.ServiceClientWS;
import fr.adfm.proxy.SC.ServiceClientWSService;

public class WsServiceClientSC {

	private ProcessContext context;
	private ServiceClientWS ws;
	
	public WsServiceClientSC(ProcessContext context){
		this.context = context;
	}
	
	public void setWs(ServiceClientWS ws) {
		this.ws = ws;
	}

	public void setReferenceTransactionPaiement(String transactionPaiement) {
		try {
			openWs();
			ws.setReferenceTransactionPaiement(context.getInput().getIdBonCommande(), transactionPaiement);
		}
		catch(Exception ex) {
			context.setException(ex);
		}
	}	
	
	public void paiementInterrompu(String info) {
		try {
			openWs();
			ws.paiementInterrompu(context.getInput().getIdBonCommande(), info);
		}
		catch(Exception ex) {
			context.setException(ex);
		}
	}	
	
	public void paiementEffectue() {
		try {
			openWs();
			ws.paiementEffectue(context.getInput().getIdBonCommande());
		}
		catch(Exception ex) {
			context.setException(ex);
		}
	}
	
	public void annulerBonCommande() {
		try {
			openWs();
			ws.annulerBonCommande(context.getInput().getIdBonCommande());
		}
		catch(Exception ex) {
			context.setException(ex);
		}
	}
	
	private void openWs() {
		if(ws != null) return;
		
		ServiceClientWSService serv = new ServiceClientWSService();
		ws = serv.getServiceClientWSPort();
	}
}
